package com.cs.user.infra.basic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cs.user.infra.basic.entity.User;
import com.cs.user.infra.basic.mapper.UserMapper;
import com.cs.user.infra.basic.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户表(AuthUser)表服务实现类
 *
 * @author makejava
 * @since 2024-09-22 17:26:24
 */
@Service("authUserService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Boolean register(User user) {
        return save(user);
    }

    @Override
    public User login(User user) {
        return lambdaQuery()
                .eq(StringUtils.isNotBlank(user.getUserAccount()),User::getUserAccount, user.getUserAccount())
                .eq(StringUtils.isNotBlank(user.getUserPassword()),User::getUserPassword, user.getUserPassword())
                .one();
    }

    @Override
    public Boolean updateUser(User user) {
        return updateById(user);
    }

    @Override
    public Boolean deleteUser(User user) {
        user.setIsDelete(1);
        return updateById(user);
    }

    @Override
    public List<User> queryPage(User user, int start, int pageSize) {
        return this.userMapper.queryPage(user, start, pageSize);
    }

    @Override
    public User queryUserByAccount(User user) {
        return lambdaQuery()
                .eq(StringUtils.isNotBlank(user.getUserAccount()), User::getUserAccount, user.getUserAccount())
                .like(StringUtils.isNotBlank(user.getUserName()), User::getUserName, user.getUserName())
                .one();
    }

}

